/*
 * #%L
 * java model
 * %%
 * Copyright (C) 2009 - 2011 prefabware.com Stefan Isele
 * %%
 * All Rights Reserved.
 * This program is dual-licensed under the GNU General Public license
 * or a commercial license.
 * You may select to use one or the other of these licenses.
 * To obtain a commercial license please contact Stefan Isele at www.stefan-isele.de
 * Any modifications to this file must keep this entire header intact.
 * Redistribution, except as permitted by the selected license, is prohibited.
 * #L%
 */
package com.prefabware.jmodel.expression;

import com.prefabware.jmodel.code.JCodeOptions;


public class JAssignment implements JExpression {
	public JLeftHandSideExpression getTarget() {
		return target;
	}

	public JExpression getExpression() {
		return expression;
	}

	private JLeftHandSideExpression target;
	private JExpression expression;

	public JAssignment(JLeftHandSideExpression target, JExpression expression) {
		super();
		this.target = target;
		this.expression = expression;
	}

	@Override
	public String toString() {
		return "JAssignment [asCode()=" + asCode(JCodeOptions.DEFAULT) + "]";
	}

	@Override
	public String asCode(JCodeOptions options) {
		//in an assignement the target is most likely a field or a variable
		//if its a field, use allways the unqulified name !
		return target.asCode(JCodeOptions.SIMPLE_NAMES) + " = " + expression.asCode(options);
	}

}
